<html>
<head><meta charset="utf-8"><title>Unannotated fn argument patterns · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html">Unannotated fn argument patterns</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214158942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214158942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bob Gebert <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214158942">(Oct 22 2020 at 08:48)</a>:</h4>
<p>I've found pattern matching to be invaluable in my work lately. I  recently bamboozled myself trying to write a function with a signature of <code>fn flim_flam_self(Flammable { a, b })</code>.  I forgot that you still have to annotate the argument to be able to pattern match on it. After fixing my mistake and renaming the function to <code>do_not_flim_flam_self</code>, I caught myself wondering what it would take to make rust accept "unannotated fn argument patterns". The "receiver" argument complicates things a bit, but other than that, is there some significant semantic hurdle to hop over to implement said "feature "?</p>



<a name="214161838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214161838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214161838">(Oct 22 2020 at 09:20)</a>:</h4>
<p>Are you referring to the fact that the signature should be <code>fn flim_flam_self(Flammable { a, b }: Flammable)</code>?</p>



<a name="214161986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214161986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214161986">(Oct 22 2020 at 09:22)</a>:</h4>
<p>One issue with leaving the type off here is that if <code>Flammable {a, b}</code> has type <code>Flammable&lt;'a&gt;</code> or <code>&amp;'a Flammable</code> or <code>&amp;'a mut &amp;'a Flammable</code> then that pattern match would also work, and something would be left undetermined</p>



<a name="214162095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214162095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214162095">(Oct 22 2020 at 09:23)</a>:</h4>
<p>personally I would rather it be the other way around, where you can just write <code>fn flim_flam_self({a, b}: Flammable)</code></p>



<a name="214217118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214217118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214217118">(Oct 22 2020 at 17:05)</a>:</h4>
<p>I recall that being discussed in some RFC maybe last year, probably the types-in-patterns one.  I think there were a bunch of objections that it can make it too hard to tell the overall type, especially when generics are involved.</p>



<a name="214217590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214217590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214217590">(Oct 22 2020 at 17:09)</a>:</h4>
<p>I agree with Mario here that omitting the name from the pattern is probably the easiest way forward here -- there have been a bunch of <a href="https://internals.rust-lang.org/t/pre-pre-rfc-syntactic-sugar-for-default-default/13234/16?u=scottmcm">threads</a> recently about wanting to be able to do that in expressions too.  See the threads about <code>_ { a, b }</code>, going back <a href="https://internals.rust-lang.org/t/pre-rfc-struct-constructor-name-inference/10960?u=scottmcm">at least a year</a>.</p>



<a name="214221804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214221804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214221804">(Oct 22 2020 at 17:41)</a>:</h4>
<p>Having it just work with <code>{ a, b }</code> is interesting, here.  There's no block-expression for that to conflict with, so it seems totally possible.</p>
<p>(I'd pondered using <code>{}</code> as <code>const{}</code> before, like in const generics.  But this use for <code>{}</code> seems far more valuable.)</p>



<a name="214243359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214243359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bob Gebert <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214243359">(Oct 22 2020 at 20:23)</a>:</h4>
<p>Mario, yeah that's what I was referring to. Your explanation totally makes sense. I hadn't thought about leaving the name off of the pattern. To be honest, that seems like a more intuitive option now that I think about it. The name really is part of the type, not so much the literal.</p>
<p>I probably should have searched back to find relevant threads. Sorry about that. Not used to the open source world.</p>
<p>scottmcm, when you say there have been threads about "wanting to do that in expressions too," I'm assuming you mean in struct literals? That was actually the next thing I was curious about. I could see how it could be unintuitive to have unnamed patterns without unnamed literals. Most of the time, I don't think of patterns and literals as two different things.</p>



<a name="214243400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214243400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bob Gebert <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214243400">(Oct 22 2020 at 20:23)</a>:</h4>
<p>Also, thank you for the quick response!</p>



<a name="214244364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214244364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214244364">(Oct 22 2020 at 20:32)</a>:</h4>
<p>I would think that type inference is harder for struct literals than struct patterns, but it is possible</p>



<a name="214259626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214259626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214259626">(Oct 22 2020 at 23:28)</a>:</h4>
<p>The problem in expressions is that <code>{ a }</code> is already a block expression, so it can't directly be shorthand for <code>Foo { a }</code>.</p>



<a name="214259817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214259817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214259817">(Oct 22 2020 at 23:31)</a>:</h4>
<p>You can make pseudo-literals of inferred type with a macro already, see <a href="https://internals.rust-lang.org/t/pre-pre-rfc-syntactic-sugar-for-default-default/13234/7?u=scottmcm">https://internals.rust-lang.org/t/pre-pre-rfc-syntactic-sugar-for-default-default/13234/7?u=scottmcm</a></p>
<p>So I don't think the inference rules are particularly problematic for it.</p>



<a name="214262721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214262721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bob Gebert <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214262721">(Oct 23 2020 at 00:23)</a>:</h4>
<p>Huh. That's really interesting. Thanks for the insight. Definitely filled in a couple gaps in my understanding of the type system and it's relationship with the parsing rules!</p>
<p>I guess there's probably no definitive solution, taking into account the ambiguity of <code>{ a }</code>. I suppose the only way to stamp out the ambiguity would be to introduce some new restrictions to the AST. The only thing I can think of is to declare that block expressions containing nothing but a single <code>Ident</code> are not allowed unless the context makes it impossible for the block to be anything other than a block expression (eg. it's a function body, the body of an <code>if</code>, etc). Definitely would be a breaking change, and one that could complicate certain kinds of RFCs down the road. For example, if someone wanted to be able to omit braces on the bodies of condition branches (I feel like  I stumbled across that request somewhere, but I have no Idea if it's something that would ever happen).</p>
<p>edit: Quotes around "breaking" removed <span aria-label="check mark" class="emoji emoji-2714" role="img" title="check mark">:check_mark:</span></p>



<a name="214262824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214262824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214262824">(Oct 23 2020 at 00:25)</a>:</h4>
<p>that's breaking in a way that would actually break stuff. definitely I've done <code>{x}</code> to force a move of <code>x</code> before</p>



<a name="214262904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214262904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bob Gebert <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214262904">(Oct 23 2020 at 00:27)</a>:</h4>
<p>This is one of the most humbling threads I've ever participated in... In the best way. Haha.</p>



<a name="214262925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214262925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214262925">(Oct 23 2020 at 00:27)</a>:</h4>
<p>stuff like that would also trip macros up, i suspect</p>



<a name="214262995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214262995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bob Gebert <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214262995">(Oct 23 2020 at 00:28)</a>:</h4>
<p>Yeah I could see that too.</p>



<a name="214263171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214263171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bob Gebert <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214263171">(Oct 23 2020 at 00:32)</a>:</h4>
<p>I feel for everyone that has to triage these threads. I can imagine it gets old responding to people who don't quite have the level of understanding required to rigorously reason about this stuff. Again, thanks for the quick response. This is super interesting to me.</p>



<a name="214269102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214269102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214269102">(Oct 23 2020 at 03:01)</a>:</h4>
<p><span class="user-mention" data-user-id="356847">@Bob Gebert</span> The usual link for why you might use <code>{x}</code>: <a href="https://bluss.github.io/rust/fun/2015/10/11/stuff-the-identity-function-does/#rust-has-dedicated-syntax-for-this">https://bluss.github.io/rust/fun/2015/10/11/stuff-the-identity-function-does/#rust-has-dedicated-syntax-for-this</a></p>
<p>The good news is that there are plenty of reasonable syntax options to disambiguate.  <code>_ { a }</code>, <code>struct { a }</code>, etc.  Or other sigil options -- <code>{= a =}</code> would work, not that I <em>like</em> that specific one.  Or moving the <code>..</code> around could work for some things too, since <code>{.., a}</code> doesn't work today.</p>



<a name="214296846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214296846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214296846">(Oct 23 2020 at 10:32)</a>:</h4>
<p>Or simply, <code>{ a, }</code> (similar to <code>()</code> and 1-tuples)</p>
<p>That being said, using a trailing comma to disambiguate seems a bit <em>too terse</em> for my taste; the <code>_{ ... }</code> syntax looks like one that has a more visible sigil (leading <code>_</code> <em>vs.</em> inner trailing <code>,</code>), which, in and on itself, intuitively conveys the right meaning: "elide" the path to the struct name.</p>



<a name="214324756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214324756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214324756">(Oct 23 2020 at 15:03)</a>:</h4>
<p>Trailing comma also doesn't seem like an appropriate disambiguator, because if you have something broken across lines you would already use a trailing comma.</p>



<a name="214324792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214324792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214324792">(Oct 23 2020 at 15:03)</a>:</h4>
<p>I personally favor the leading _ as well.</p>



<a name="214429320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214429320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214429320">(Oct 24 2020 at 13:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns/near/214324756">said</a>:</p>
<blockquote>
<p>Trailing comma also doesn't seem like an appropriate disambiguator, because if you have something broken across lines you would already use a trailing comma.</p>
</blockquote>
<p>How so?</p>



<a name="214433885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214433885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214433885">(Oct 24 2020 at 15:40)</a>:</h4>
<p><span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> Rust syntax already allows an optional trailing comma on all comma-separated lists, including the contents of braces. And the standard Rust style includes the trailing comma whenever such a list is broken across lines.</p>



<a name="214433917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214433917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214433917">(Oct 24 2020 at 15:41)</a>:</h4>
<p>So we shouldn't give any sort of semantic significance to the trailing comma.</p>



<a name="214434841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214434841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214434841">(Oct 24 2020 at 16:01)</a>:</h4>
<p>But in the case of anonymous struct / braced expression ambiguity, only the former can accept a comma-separated list. That is, <code>{ a, }</code> <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=6bee3240726118e7b632c8ae8a04bbd0">currently isn't a valid expression</a></p>



<a name="214434984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214434984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214434984">(Oct 24 2020 at 16:04)</a>:</h4>
<p>But then the trailing comma becomes non-optional, which would be different from every other context in which Rust currently allows a trailing comma. And, for instance, if someone reformatted the line to be shorter, and then naturally deleted the trailing comma when they joined the lines, that would change the meaning of the expression.</p>



<a name="214434985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214434985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214434985">(Oct 24 2020 at 16:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns/near/214433917">said</a>:</p>
<blockquote>
<p>So we shouldn't give any sort of semantic significance to the trailing comma.</p>
</blockquote>
<p>there is one exception: <code>(a,)</code> vs <code>(a)</code></p>



<a name="214434996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214434996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214434996">(Oct 24 2020 at 16:04)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> Fair point. Rare, but true.</p>



<a name="214435291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214435291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214435291">(Oct 24 2020 at 16:11)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232018">Daniel Henry-Mantilla</span> <a href="#narrow/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns/near/214296846">said</a>:</p>
<blockquote>
<p>Or simply, <code>{ a, }</code> (similar to <code>()</code> and 1-tuples)</p>
</blockquote>
<p>I guess I was a bit too terse with that, but the parallel to <code>(a,)</code> (1-tuples) is precisely what motivated this syntax for 1-field structs.</p>
<p>Anyways, we are just nitpicking about technical semantics: I do agree that <code>(a,)</code> is unfortunate in and on itself, and only there for historical reasons (most languages use <code>()</code> to both offer explicit precedence and for tuple delimiters), so let's not "there is precendence for this suboptimal thing being done, so let's keep doing it"; I personally also prefer <code>_{ a }</code> syntax (with a personal preference for that lack of whitespace after <code>_</code>).</p>



<a name="214435554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214435554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214435554">(Oct 24 2020 at 16:16)</a>:</h4>
<p>Interesting. Why the lack of whitespace, given that what the underscore replaces normally has whitespace after it?</p>



<a name="214436436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Unannotated%20fn%20argument%20patterns/near/214436436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Unannotated.20fn.20argument.20patterns.html#214436436">(Oct 24 2020 at 16:34)</a>:</h4>
<p>Hard to really say why, I have a gut feeling that in this case it feels "a bit better" <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> I'd say that it helps convey the idea that the <code>_</code> is attached to that braced body, in a way that may not be that obvious / seems a bit more noisy <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="n">FOO</span>: <span class="nc">MyStruct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">foo</span>: <span class="o">..</span><span class="p">,</span><span class="w"> </span><span class="n">bar</span>: <span class="o">..</span><span class="w"> </span><span class="p">};</span><span class="w"></span>

<span class="k">const</span><span class="w"> </span><span class="n">BAR</span>: <span class="nc">MyStruct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">_</span><span class="p">{</span><span class="w"> </span><span class="n">foo</span>: <span class="o">..</span><span class="p">,</span><span class="w"> </span><span class="n">bar</span>: <span class="o">..</span><span class="w"> </span><span class="p">};</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">x</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">foo</span><span class="p">,</span><span class="w"> </span><span class="n">bar</span><span class="w"> </span><span class="p">}</span>: <span class="nc">MyStruct</span><span class="p">,</span><span class="w"> </span><span class="o">..</span><span class="p">.);</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">bar</span><span class="p">(</span><span class="n">x</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="p">{</span><span class="w"> </span><span class="n">foo</span><span class="p">,</span><span class="w"> </span><span class="n">bar</span><span class="w"> </span><span class="p">}</span>: <span class="nc">MyStruct</span><span class="p">,</span><span class="w"> </span><span class="o">..</span><span class="p">.);</span><span class="w"></span>
</code></pre></div>

<p>Okay, after "inner gut introspection" (that sounds weird), I find that in the <code>const</code> case, both "feel the same" to me, but in the function param case, I do prefer <code>bar</code>.</p>
<p>Anyways, I don't want to pollute the thread with this personal rambling more than I already have (I apologize for that), since it is neither the moment nor the place to do that. It's not like I have a strong preference anyways <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>